﻿using System;
using __Able.Core.Configuration;
using __Able.Network.Events;
using __Able.Network.Manager;
using __Able.Network.Packet;
using __Able.Network.Utils;

namespace __Able.Network
{
    public class Channel
    {
        public Channel()
        {
            //PacketManager = new PacketManager(this);
            ConnectionManager = new ConnectionManager(this);
            //KeepAliveManager = new KeepAliveManager(this);
            this.User = new User();
        }
        /// <summary>
        /// 用户信息
        /// </summary>
        public User User { get; private set; }
        /// <summary>
        /// 连接管理
        /// </summary>
        /// <value></value>
        public ConnectionManager ConnectionManager { get; private set; }
        /// <summary>
        /// 包管理
        /// Gets or sets the packet manager.
        /// </summary>
        /// <value>The packet manager.</value>
        //public PacketManager PacketManager { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        //public KeepAliveManager KeepAliveManager { get; private set; }
        /// <summary>
        /// 错误事件
        /// </summary>
        public event EventHandler<EventArgs<ErrorPacket>> Error;
        /// <summary>
        /// Called when [error].
        /// </summary>
        /// <param name="e">The e.</param>
        internal void OnError(EventArgs<ErrorPacket> e)
        {
            if (Error != null)
                Error(this, e);
        }
        /// <summary>
        /// 
        /// </summary>
        public int Port
        {
            get
            {
                int port;
                if (int.TryParse(ConfigManager.GlobalAppSettings["Port"], out port))
                    return port;
                return 8080;
            }
        }
    }
}
